package com.lsec.springbootinit.model.common;

import com.lsec.springbootinit.exception.enums.TypicalCode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
 * 统一异常
 *
 * @author Cherry
 * @date 2023-03-03 14:42
 */

@Schema(description = "统一异常")
@Getter
@EqualsAndHashCode(callSuper = true)
public class ServiceException extends RuntimeException {

    /**
     * 业务返回错误码
     */
    @Schema(description = "业务返回错误码")
    private Integer code;

    /**
     * 业务错误消息
     */
    @Schema(description = "业务错误消息")
    private String message;

    public ServiceException(String msg) {
        this.message = msg;
    }

    public ServiceException(Integer code) {
        this.code = code;
    }

    public ServiceException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public ServiceException(TypicalCode code) {
        this.code = code.getCode();
        this.message = code.getMessage();
    }


    public static ServiceException exception(String msg) {
        return new ServiceException(msg);
    }

    public static ServiceException exception(Integer code) {
        return new ServiceException(code);
    }

    public static ServiceException exception(Integer code, String message) {
        return new ServiceException(code, message);
    }

    public static ServiceException exception(TypicalCode statusEnum) {
        return new ServiceException(statusEnum);
    }



}
